{extend name="style/base"/}

{block name="resources"}
{/block}

{block name="main"}
<div class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">站点公钥</label>
        <div class="layui-input-inline">
            <p class="nc-input-text">{$info.app_key}</p>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">站点私钥</label>
        <div class="layui-input-block">
            <div class="layui-input-inline">
                <input type="text" name="app_secret" id="app_secret" value="{$info.app_secret}" lay-verify="app_secret" autocomplete="off" placeholder="请输入站点私钥" class="layui-input nc-len-long" readonly>
            </div>
            <button class="layui-btn layui-btn-primary" onclick="changeSecret()">重置私钥</button>
        </div>
        <div class="layui-form-mid layui-word-aux">站点秘钥是用户进行配置app或者小程序接口进行加密或者解密使用，请谨慎保管 </div>
    </div>
    <div class="nc-form-row">
        <input type="button" value="保存" class="layui-btn" lay-submit="" lay-filter="save"/>
        <a href="javascript:history.back(-1);" class="layui-btn layui-btn-primary">返回</a>
    </div>
</div>

{/block}

{block name="script"}
<script type="text/javascript">
    layui.use(['form'], function () {
        var form = layui.form;

        form.verify({
            app_secret: function (value) {
                if (value == '') {
                    return '请设置站点秘钥';
                }
            }
        });
	
		var repeat_flag = false;//防重复标识
        form.on('submit(save)', function (data) {
            if(repeat_flag) return;
			repeat_flag = true;
            $.ajax({
                url: "{:url('sitehome/manager/secretKeyManage')}",
                data: data.field,
                type: "post",
                dataType : "JSON",
                success: function (res) {
                	if(res.code != 0) repeat_flag = false;
                    layer.msg(res.message);
					location.reload();
                }
            })
        });
    });

    function changeSecret(){
        $.ajax({
            type : "post",
            url : "{:url('sitehome/manager/getRandom')}",
            data : {},
            success : function(data) {
                $("#app_secret").val(data);
            }
        });
    }
</script>
{/block}